package com.itheima.chinamobileai.tool;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.chinamobileai.domain.ComboPackage;
import com.itheima.chinamobileai.service.IComboPackageService;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Component
public class MyTool {
    @Autowired
    private IComboPackageService comboPackageService;

    @Tool(description = "多条件查询套餐：支持月租区间、流量模糊匹配、通话时长区间、附加服务模糊匹配")
    public List<ComboPackage> queryComboPackage(@ToolParam(required = false, description = "套餐查询条件") ComboPackageQuery query) {
        if (query == null) {
            //如果查询条件全为空
            return comboPackageService.list();//直接查全部
        }
        QueryWrapper<ComboPackage> wrapper = new QueryWrapper<>();
            // 1.月租区间
            if (query.getMinMonthlyRent() != null) {
                wrapper.ge("monthly_rent", query.getMinMonthlyRent());
            }
            if (query.getMaxMonthlyRent() != null) {
                wrapper.le("monthly_rent", query.getMaxMonthlyRent());
            }
            // 2.流量模糊匹配
            if (StrUtil.isNotBlank(query.getFlow())) {
                wrapper.like("flow", query.getFlow());
            }
            // 3.通话时长区间
            if (query.getMinCallDuration() != null) {
                wrapper.ge("call_duration", query.getMinCallDuration());
            }
            // 4. 附加服务模糊匹配（如“宽带”“副卡”）
            if (StrUtil.isNotBlank(query.getAdditionalService())) {
                wrapper.like("additional_service", query.getAdditionalService());
            }
        return comboPackageService.list(wrapper);
    }
}
